package com.ztgf.commodity.service;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.ztgf.commodity.common.config.YmlConfig;
import com.ztgf.commodity.mapper.CommodityApplyAgentLogMapper;
import com.ztgf.commodity.models.dto.CommodityApplyAgentLogDTO;
import com.ztgf.commodity.models.service.ICommodityApplyAgentLogService;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.scheduling.annotation.Async;

import javax.annotation.Resource;

/*
 * @author: chenyu.wang
 * @date: 2020-09-11
 * @description:
 */
@DubboService
public class CommodityApplyAgentLogServiceImpl extends ServiceImpl<CommodityApplyAgentLogMapper, CommodityApplyAgentLogDTO> implements ICommodityApplyAgentLogService {

    @Resource
    private YmlConfig ymlConfig;

    /*
     * @description:保存代理申请日志
     * @author: chenyu.wang
     * @date: 2020-09-11
     * @return:
     */
    @Async
    @Override
    public void add(CommodityApplyAgentLogDTO dto) {
        CommodityApplyAgentLogDTO logDTO = new CommodityApplyAgentLogDTO();
        if (dto.getApplyAgentId() != null) {
            logDTO.setApplyAgentId(dto.getApplyAgentId());
        }
        if (dto.getManagerUserId() != null) {
            logDTO.setManagerUserId(dto.getManagerUserId());
        }
        if (dto.getDealState() != null) {
            logDTO.setDealState(dto.getDealState());
        }
        if (StringUtils.isNotBlank(dto.getDealContent())) {
            logDTO.setDealContent(dto.getDealContent());
        }
        logDTO.setId(ymlConfig.getPkId());
        insert(logDTO);
    }
}
